package day07Exercise;

import java.util.Locale;
import java.util.Random;
import java.util.Scanner;



public class Day07StandardExercise03 {
    public static void main(String[] args) {
        /*
        方法的重载
         */
        /**
         * 猜数字小游戏
         * 训练目标: while(true)自造死循环
         */
        /*
        Scanner scanner=new Scanner(System.in);
        int random=(int)(Math.random()*100);
        System.out.println(random);
        while (true){
            System.out.println("猜吧");
            int guess = scanner.nextInt();
            if (guess>random){
                System.out.println("猜大了");
            }else if (guess<random){
                System.out.println("猜小了");
            }else {
                System.out.println("猜对了");
                break;
            }
        }

         */
        /*
 * 需求:生成?位验证码(大写字母、小写字母、数字)
 *
 */
        /*
        String code=generateVerificationCode(6);
        System.out.println(code);
      Boolean result=  checkVerificationCode(code);
        System.out.println(result);

         */
/**
 * 需求:----------常见面试题
 *   找到2到100之间的所有素数(质数)
 *   素数:除了1和它本身外，不能被其它任何自然数整数的数
 *
 */
/*
//int number=100;
       int[] num= primeNumber();
       for (int i=0;i<num.length;i++){
           if (num[i]!=0){
               System.out.print(num[i]+"\t");
           }

       }
 */
        /**
需求：
  机票价格按照淡季旺季、头等舱、商务舱和经济舱收费，
  输入机票原价、月份和头等舱、商务舱或经济舱，
  其中旺季（5-10月）头等舱9折，商务舱85折，经济舱8折，
  淡季（11月到来年4月）头等舱7折，商务舱65折，经济舱6折，
  最终输出机票价格
 */
        /*
//        double price=1000.0;
//        int mouth=3;
//        int type=3;
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入原价:");
        double price = scanner.nextDouble();
        System.out.println("请选择月份：");
        int mouth = scanner.nextInt();
        System.out.println("请选择飞机票类型:");
        int type=scanner.nextInt();

        double discountPrice=calAirPrice0(price,mouth,type);
        System.out.println("折后价格:"+discountPrice);

         */
        /**
         * 需求:
         * <<主持人大赛>>有6名评委给选手打分，要求分数范围为0到100之间的整数。
         * 选手的最后得分为：去掉最高分、最低分后的4个评委的平均分
         */
       double[] scores= enterScore();
      double avg= calTotalAvg(scores);
        System.out.println("平均分："+avg);



    }

    private static double calTotalAvg(double[] scores) {
        double max=scores[0];
        double min=scores[0];
        double total=0.0;
        for (int i=0;i<scores.length;i++){
            if (scores[i]>max){
                max=scores[i];
            }
            if (scores[i]<min){
                min=scores[i];
            }
            total+=scores[i];
        }
        return (total-max-min)/(scores.length-2);
    }

    private static double[] enterScore() {
        System.out.println("生成6位老师给的分数：");
        double[] scores=new double[6];
        for (int i=0;i<6;i++){
            scores[i]=(int)(Math.random()*100+1);
            System.out.println(scores[i]);
        }
        return scores;
    }


    private static double calAirPrice0(double price, int mouth, int type) {
        Scanner scanner=new Scanner(System.in);
        if (mouth<1 ||mouth>12){
            return -1;
        }
        if(type<1 || type>3){
            return -1;
        }

        if (mouth>=5 &&mouth<=10){
            switch (type){
                case 1:
                     price*=0.9;
                    break;
                case 2:
                    price*=0.85;
                    break;
                case 3:
                     price*=0.8;
                    break;
            }

        }else {
            switch (type){
                case 1:
                     price*=0.7;
                    break;
                case 2:
                     price*=0.65;
                    break;
                case 3:
                     price*=0.6;
                    break;
            }
        }

     return price;
    }

    private static int[] primeNumber() {
        int[] arr=new int[100];
        for (int i=2;i<=100;i++){
            boolean flag=true;
            for (int num=2;num<i/2;num++){
                if (i%num==0){
                    flag=false;
                    break;
                }
            }
            if (flag){
                arr[i-2]=i;
            }


        }
        return arr;

    }

    private static Boolean checkVerificationCode(String code) {
        String verificationCOde = code.toUpperCase(Locale.ROOT);
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入验证码：");
        String inputCode = scanner.nextLine();
         inputCode= inputCode.toUpperCase();
         if (inputCode.equals(verificationCOde)){
             return true;
         }else {
             return false;
         }

    }

    private static String generateVerificationCode(int len) {
        String code="";
        //62个字符
        char[] chs={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
                'p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G',
                'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
                '0','1','2','3','4','5','6','7','8','9'};
        Random random=new Random();
        for (int i=0;i<len;i++){
//获取随机字符数组中的随机下标
            int index = random.nextInt(chs.length);
            code+=chs[index];

        }
        return code;

    }

    public static void show(){}
    public static void show(String name){}
    public static void show(String name,int age){}
    public static void show(int age){}
    public static void show(int age,String name){}
//    public static int show(){}
//    public static void show(String address){}

}
